#pragma once
#include <string>

class Solution {
public:
	int lengthOfLongestSubstring(std::string s) {
		std::string::iterator it = s.begin();
		auto rit = it + 1;

		int max_len = 1;
		int len_count = 1;

		while (it != s.end() && rit != s.end())
		{
			std::string* str = new std::string[s.length()];
			str->push_back(*it);
			if (*rit != *it)
			{
				bool isExisted = IsExisted(str, *rit);
				if (isExisted == false)
				{
					str->push_back(*rit);
					len_count++;
					rit++;
				}
				else
				{
					max_len = len_count > max_len ? len_count : max_len;
					len_count = 1;
					it++;
					rit = it + 1;
				}
			}
		}
	}

	bool IsExisted(std::string str[], char c)
	{
		for (auto it = str->begin(); it != str->end(); it++)
		{
			if (*it == c)  return true;
			return false;
		}
	}
};